package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bo.gh.CreateKeyWordBO;
import com.kuang.demo.pojo.KeyWordPOJO;
import com.kuang.demo.service.KeyWordService;
import com.kuang.demo.vo.CreateKeyWordVO;
import com.kuang.demo.vo.QueryKeyWordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/11/3 15:32
 */
@RestController
@RequestMapping("admin/keyword")
public class KeyWordController {
    @Autowired
    KeyWordService keyWordService;

    @GetMapping("list")
    //GET http://182.92.235.201:8083/admin/keyword/list?page=1&limit=20&keyword=%E7%A1%AC%E4%BB%B6&url=124&sort=add_time&order=desc HTTP/1.1
    public BaseRespVo keyWordList(Integer page,Integer limit,String keyword,String url,String sort,String order){
        QueryKeyWordVO queryKeyWordVO = new QueryKeyWordVO();
        Map<String, Object> keyWordInfo = keyWordService.queryKeyWordList(page,limit,keyword,url,sort,order);
        queryKeyWordVO.setItems((List<QueryKeyWordVO.ItemsBean>) keyWordInfo.get("issueList"));
        queryKeyWordVO.setTotal((Integer) keyWordInfo.get("total"));
        return BaseRespVo.ok(queryKeyWordVO);
    }

    @PostMapping("create")
    public BaseRespVo createKeyWord(@RequestBody CreateKeyWordBO createKeyWordBO){
        CreateKeyWordVO createKeyWordVO = keyWordService.createKetWord(createKeyWordBO);
        return BaseRespVo.ok(createKeyWordVO);
    }

    @PostMapping("update")
    public BaseRespVo updateKeyWord(@RequestBody KeyWordPOJO keyWordPOJO){
        KeyWordPOJO keyWordPOJO1 = keyWordService.updateKeyWord(keyWordPOJO);
        return BaseRespVo.ok(keyWordPOJO1);
    }

    @PostMapping("delete")
    public BaseRespVo deleteKeyWord(@RequestBody KeyWordPOJO keyWordPOJO){
        keyWordService.deleteKeyWord(keyWordPOJO);
        return BaseRespVo.ok();
    }
}
